<%--
  Created by IntelliJ IDEA.
  User: 62585
  Date: 2021/3/28
  Time: 23:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>ajax</title>
    <script type="text/javascript">
        function ajaxRequest() {
            var xmlHttpRequest = new XMLHttpRequest();
            xmlHttpRequest.open("GET", "http://localhost:8080/json/AjaxServlet", true);
            xmlHttpRequest.onreadystatechange = function () {
                if (xmlHttpRequest.readyState === 4 && xmlHttpRequest.status === 200) {
                    var resp = JSON.parse(xmlHttpRequest.responseText);
                    document.getElementById("response").innerHTML = resp.id + " : " + resp.name;
                }
            }
            xmlHttpRequest.send();
        }
    </script>
</head>
<body>
<div id="response"></div>
<button id="ajax" name="ajax" onclick="ajaxRequest()">ajax</button>
</body>
</html>
